home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000144_icon-group-sender _Wed Jun 23 09:06:16 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id JAA10769
  4.     for icon-group-addresses; Wed, 23 Jun 1999 09:05:33 -0700 (MST)
  5. Message-Id: <199906231605.JAA10769@baskerville.CS.Arizona.EDU>
  6. Date: Wed, 23 Jun 1999 12:31:37 +1200 (NZST)
  7. From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
  8. To: dgamey@ca.ibm.com, oikonomou@att.com
  9. Subject: Re: Assertions in Icon
  10. Cc: icon-group@optima.CS.Arizona.EDU
  11. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  12. Status: RO
  13.  
  14.     >Does anyone have a suggestion about how to implement a procedure "assert",
  15.     >which, when called with an expression "e" as argument, implements
  16.     >
  17.     >         e | stop("Assertion on line ", &line, " failed!")
  18.     >
  19.     >Here &line should be the line on which assert(e) appears.
  20.     
  21.     
  22. The obvious answer is "do it the way C does; use a preprocessor".
  23. In what follows, I'm going to use M4, because
  24.  - it's the traditional UNIX macro processor
  25.  - there are two free versions: GNU M4 and pdm4
  26.  - I know it fairly well.
  27.  
  28. Method 1.
  29.  
  30.     define(assert, `real_assert((`$1'), &line)')
  31.  
  32. where the real_assert procedure is plain Icon code.    
  33.  
  34. Method 2.
  35.  
  36.     define(assert, `((`$1') | stop("Assertion on line ", &line, " failed!"))')
  37.  
  38. where now everything is in the macro.
  39.  
  40. That's the quick and easy way.  A better way, long term, would be for
  41. someone to patch the Icon translator to support `assert'.  It's *FAR*
  42. too powerful a debugging tool to leave out of the language much longer.
  43.  
  44.  
  45.